home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / prospero / propsero.lha / prospero-beta.4.2e / user / vfsetup.c < prev    next >
C/C++ Source or Header  |  1992-02-10  |  3KB  |  125 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <uw-copyright.h>.
  6.  */
  7.  
  8. #include <uw-copyright.h>
  9.  
  10. #include <stdio.h>
  11. #include <strings.h>
  12.  
  13. #include <psite.h>
  14. #include <pfs.h>
  15. #include <pcompat.h>
  16. #include <perrno.h>
  17. #include <pmachine.h>
  18.  
  19. int    pfs_debug = 0;
  20.  
  21. char    *getenv();
  22.  
  23. main(argc,argv)
  24.     int        argc;
  25.     char    *argv[];
  26.     {
  27.     int        reset = 0;
  28.     int        tmp;
  29.  
  30.     char        vsdesc_host[100];
  31.     char        vsdesc_file[100];
  32.     char        vsname[100];
  33.     char        *progname = argv[0];
  34.     char        vsfname[100];
  35.     FILE        *vsdesc;
  36.     char        *colon;
  37.  
  38.     *vsdesc_host = '\0';
  39.     *vsdesc_file = '\0';
  40.     *vsname = '\0';
  41.  
  42.     if ((argc > 1) && (strncmp(argv[1],"-D",2) == 0)) {
  43.         pfs_debug = 1; /* Default debug level */
  44.         sscanf(argv[1],"-D%d",&pfs_debug);
  45.         argc--;argv++;
  46.     }
  47.  
  48.     if((argc == 4) && (strcmp(argv[1],"-n") == 0)) {
  49.         /* parse the native values */
  50.         strcpy(vsdesc_host,argv[2]);
  51.         strcpy(vsdesc_file,argv[3]);
  52.     }
  53.     else if ((argc == 3) && (strcmp(argv[1],"-r") == 0)) {
  54.         /* parse name of the vs and look it up, but ignore    */
  55.         /* the present virtual system, and do the search from */
  56.         /* the initial one. (reset to starting configuration) */
  57.         strcpy(vsname,argv[2]);
  58.         reset = 1;
  59.     }
  60.     else if ((argc == 3) && (strcmp(argv[1],"-v") == 0)) {
  61.         /* parse name of the vs and look it up, but treat the */
  62.         /* name as an absolute name relative to current       */
  63.         /* location instead of relative to VIRTUAL-SYSTEMS    */
  64.         strcpy(vsname,argv[2]);
  65.     }
  66.     else if (argc == 2) {
  67.         /* parse the name of the vs and look it up.           */
  68.         /* Kludge: if VSWORK_HOST is defined, then the search */
  69.         /* will be relative to our current virtual system, so */
  70.         /* the name should be prepended with /VIRTUAL-SYSTEMS */
  71.         /* Aditionally, if the name includes any namespace    */
  72.         /* operators, they should all precede the /VIRT...    */
  73.         strcpy(vsname,argv[1]);
  74.         colon = rindex(vsname,':');
  75.         if(colon) *(colon+1) = '\0';
  76.         else *vsname = '\0';
  77.         strcat(vsname,(pget_wdhost() ? "/VIRTUAL-SYSTEMS/" : ""));
  78.         colon = rindex(argv[1],':');
  79.         if(colon) strcat(vsname,colon+1);
  80.         else strcat(vsname,argv[1]);
  81.     }
  82.     else if ((argc == 1) || ((argc == 3) && (strcmp(argv[1],"-f") == 0))) {
  83.         if(argc == 1) {
  84.         strcpy(vsfname,getenv("HOME"));
  85.         strcat(vsfname,"/.virt-sys");
  86.         }
  87.         else strcpy(vsfname,argv[2]);
  88.         if((vsdesc = fopen(vsfname,"r")) == NULL) {
  89.         fprintf(stderr,"%s: Can't open system description file - %s\n",
  90.             progname,vsfname);
  91.         exit(1);
  92.         }
  93.         
  94.         fscanf(vsdesc,"%s %s",vsdesc_host,vsdesc_file);
  95.  
  96.         fclose(vsdesc);
  97.  
  98.     }
  99.     else {
  100.         fprintf(stderr,"usage: %s [-n host file, -f file, [-r,v] vsname]\n",
  101.             progname);
  102.         exit(1);
  103.     }
  104.  
  105.     tmp = vfsetenv((reset ? NULL : vsdesc_host),
  106.                (reset ? NULL : vsdesc_file),
  107.                vsname);
  108.  
  109.     if(tmp == VFSN_NOT_A_VS) {
  110.         fprintf(stderr,"%s: %s is not a virtual system\n",progname,
  111.             (vsname ? vsname : vsdesc_file));
  112.         exit(1);
  113.     }
  114.     else if(tmp) {
  115.         fprintf(stderr,"%s",progname);
  116.         perrmesg(" failed: ", tmp, NULL);
  117.         exit(1);
  118.     }
  119.  
  120.     if(pwarn) pwarnmesg("WARNING: ",0,NULL);
  121.  
  122.     pprint_shellstring(0x1F);
  123.     exit(0);
  124.     }
  125.